package nongchang.kuaijiecaifu.com.ncapp_android.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;



import ezy.lite.util.ContextUtil;
import nongchang.kuaijiecaifu.com.ncapp_android.R;
import nongchang.kuaijiecaifu.com.ncapp_android.common.activity.BaseActivity;

public class WebViewActivity extends BaseActivity {
    public static void start(Context context, String title, String url) {
        Bundle bundle = new Bundle();
        bundle.putString("TITLE", title);
        bundle.putString("URL", url);
        ContextUtil.startActivity(context, WebViewActivity.class, bundle);
    }

    private WebView _webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String title = getIntent().getExtras().getString("TITLE");
        String url = getIntent().getExtras().getString("URL");

        setContentView(R.layout.activity_webview);
        setupToolbarWithHome(R.id.toolbar);
//        homeAsUp();
        setTitle(title);


        _webView = (WebView)findViewById(R.id.webview);
        WebSettings settings = _webView.getSettings();
        settings.setJavaScriptEnabled(true);
//        _webView.removeJavascriptInterface("searchBoxJavaBridge_");
        _webView.loadUrl(url);
    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            if (_webView.canGoBack()) {
                _webView.goBack();
            } else {
                finish();
            }
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
